package com.jamesacurtis.MyBudget;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

public class AddExpense extends Activity {

	//Your member variable declaration here
    Button addButton;
    //expense amount 
    private int expenseAmount = 0;
    
    
    RadioGroup categoryGroup, occuranceGroup;
    RadioButton fButton, entertain, hobby, cloth, rent, dontknow, taxes, trans;
    RadioButton once,biweekly, monthly, dontknowoc;
    android.view.View.OnClickListener myRadioButtonListener;
    
    //String of category and occurrence 
    public String cat, occ;
    
    
	
    
    // Called when the activity is first created.
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.new_expense);
        
       //set up radioButton 
        this.fButton = (RadioButton)findViewById(R.id.foodradio);
        this.entertain = (RadioButton)findViewById(R.id.entertain);
        this.hobby = (RadioButton)findViewById(R.id.hobby);
        this.cloth = (RadioButton)findViewById(R.id.cloth);
        this.rent = (RadioButton)findViewById(R.id.rent);
        this.dontknow = (RadioButton)findViewById(R.id.dontknow);
        this.taxes = (RadioButton)findViewById(R.id.taxes);
        this.trans = (RadioButton)findViewById(R.id.trans);
        // entertain, hobby, cloth, rent, dontknow, taxes, trans;
        //once,biweekly, monthly, dontknowoc
        this.once = (RadioButton)findViewById(R.id.once);
        this.biweekly = (RadioButton)findViewById(R.id.entertain);
        this.monthly = (RadioButton)findViewById(R.id.hobby);
        this.dontknowoc = (RadioButton)findViewById(R.id.dontknowoc);
            
        addButton = (Button)findViewById(R.id.add_button);
    	addButton.setOnClickListener(new Button.OnClickListener() {
			    //TODO: add real action
    		    //get radios 
			    public void onClick (View v){
			    	 setOccur();
			    	 setCat();
			    	 addExpense();
			    }
		 });
		
	
	}
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu){
		 super.onCreateOptionsMenu(menu);
		 
		 menu.add(0, menu.FIRST, menu.NONE, "HOME");
		 menu.add(0, menu.FIRST+1, menu.NONE, "EXIT");
		
		return true; 
	}
		
private void addExpense(){
		
		AlertDialog.Builder alert = new AlertDialog.Builder(this);

		alert.setTitle("Add Expense");
		alert.setMessage("Please Enter Amount");

		// Set an EditText view to get user input 
		final EditText input = new EditText(this);
		alert.setView(input);

		alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
		public void onClick(DialogInterface dialog, int whichButton) {
		  String value = input.getText().toString();
		  //convert that value to int 
          expenseAmount = Integer.parseInt(value);	
          Toast.makeText(AddExpense.this, "Amount Entered: " + expenseAmount + " " +cat + " " + occ, Toast.LENGTH_LONG).show();
          
		  }
		});

		alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
		  public void onClick(DialogInterface dialog, int whichButton) {
		    // Canceled.
			  Toast.makeText(AddExpense.this, "Amount Entered: " + expenseAmount, Toast.LENGTH_LONG).show();
		  }
		});

		alert.show();
		
		
	}

	



private void setCat() {
		if(fButton.isChecked()){
			 cat = "Food";
			 
		 }
		 if(entertain.isChecked()){
			 cat = "Entertainment";
			 
		 }
		 if(hobby.isChecked()){
			 cat = "Hobby";
			 
		 }if(cloth.isChecked()){
			 cat = "Cloth";
			 
		 }
		 if(rent.isChecked()){
			 cat = "rent";
			 
		 }
		 if(dontknow.isChecked()){
			 cat = "DONTKNOW";
			 
		 }
		 if(taxes.isChecked()){
			 cat = "Taxes";
			 
		 }
		 if(trans.isChecked()){
			 cat = "Transportation";
			 
		 }
	}



private void setOccur() {
	if(once.isChecked()){
		 occ = "Once";
		
	 }
	 if(biweekly.isChecked()){
		 occ = "Bi-Weekly";
		
	 }
	 if(monthly.isChecked()){
		 occ = "Monthly";
		
	 }
	 if(dontknowoc.isChecked()){
		 occ = "Dontknow";
		
	 }
}
}